package de.wittekind.bundesjugendspiele.client.management.model;

import java.io.IOException;
import java.util.GregorianCalendar;
import de.wittekind.bundesjugendspiele.server.interfaces.Schueler;
import de.wittekind.bundesjugendspiele.server.interfaces.Schueler.Gender;
import de.wittekind.bundesjugendspiele.server.interfaces.Discipline;

public class DisciplineUtils {
	public static Discipline givePossibleDisciplines(Schueler s, Discipline d) throws IOException
	{
		if(d.isGroup())
		{
			Discipline[] disToTest = d.getDisciplines();
			
			int diff = GregorianCalendar.getInstance().get(GregorianCalendar.YEAR)-s.getBirthday().get(GregorianCalendar.YEAR);
			
			if(s.getGender()==Gender.FEMALE&&d.hasDiscipline(Discipline.AUSDAUER800))
			{
				return Discipline.AUSDAUER800;
			} else if(s.getGender()==Gender.MALE&&d.hasDiscipline(Discipline.AUSDAUER1000))
			{
				return Discipline.AUSDAUER1000;
			}
			if(s.getGender()==Gender.FEMALE)
			{
				if(diff<13)
				{
					if(d.hasDiscipline(Discipline.SPRINT50))
					{
						return Discipline.SPRINT50;
					} else if(d.hasDiscipline(Discipline.HOCHSPRUNG))
					{
						return Discipline.HOCHSPRUNG;
					} else if(d.hasDiscipline(Discipline.WURF80))
					{
						return Discipline.WURF80;
					} else 
					{
						return null;
					}
				} else if(diff<14)
				{
					if(d.hasDiscipline(Discipline.SPRINT75))
					{
						return Discipline.SPRINT50;
					} else if(d.hasDiscipline(Discipline.HOCHSPRUNG))
					{
						return Discipline.HOCHSPRUNG;
					} else if(d.hasDiscipline(Discipline.WURF80))
					{
						return Discipline.WURF80;
					} else 
					{
						return null;
					}
				} else if(diff<15)
				{
					if(d.hasDiscipline(Discipline.SPRINT75))
					{
						return Discipline.SPRINT50;
					} else if(d.hasDiscipline(Discipline.HOCHSPRUNG))
					{
						return Discipline.HOCHSPRUNG;
					} else if(d.hasDiscipline(Discipline.WURF200))
					{
						return Discipline.WURF200;
					} else if(d.hasDiscipline(Discipline.STOSS3000))
					{
						return Discipline.STOSS3000;
					} else 
					{
						return null;
					}
				} else if(diff<16)
				{
					if(d.hasDiscipline(Discipline.SPRINT100))
					{
						return Discipline.SPRINT100;
					} else if(d.hasDiscipline(Discipline.HOCHSPRUNG))
					{
						return Discipline.HOCHSPRUNG;
					} else if(d.hasDiscipline(Discipline.STOSS3000))
					{
						return Discipline.STOSS3000;
					} else 
					{
						return null;
					}
				} else
				{
					if(d.hasDiscipline(Discipline.SPRINT100))
					{
						return Discipline.SPRINT100;
					} else if(d.hasDiscipline(Discipline.HOCHSPRUNG))
					{
						return Discipline.HOCHSPRUNG;
					} else if(d.hasDiscipline(Discipline.STOSS4000))
					{
						return Discipline.STOSS4000;
					} else 
					{
						return null;
					}
				}
			}
			
			return d;
		} else
		{
			return d;
		}
	}
}
